//package com.baizhi.cmfz.shiro;
//
//import com.baizhi.cmfz.dao.AdminDao;
//import com.baizhi.cmfz.entity.Admin;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.realm.AuthenticatingRealm;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpSession;
//
//public class AuthenRealm3 extends AuthenticatingRealm {
//
//	@Resource
//	private AdminDao adminDao;
//
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
////		1.强转为UsernamePasswordToken
//		UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken)authenticationToken;
////		2.从token中获取用户信息
//		String username = usernamePasswordToken.getUsername();
////		3.查询数据库
//		Admin admin = adminDao.selectAdminByNameAndPassword(username);
////		4.判断admin是不是为空
//		if (admin != null) {
////			在这里获取session将用户信息放入session中  也可以使用shiro的session（推荐）
//			ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//			HttpSession session = requestAttributes.getRequest().getSession();
//			session.setAttribute("admin",admin);
////			5。不为空的情况下将数据信息封装在SimpleAuthenticationInfo中
//			return new SimpleAuthenticationInfo(admin.getAdminName(),admin.getAdminPassword(),this.getName());
//		}
////		6.为空的情况下返回null;
//		return null;
//	}
//}
